
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:school_safe_teacher/constans/constants.dart';
import 'package:school_safe_teacher/constans/route_constants.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/utils/sp_utils.dart';


import 'action.dart';
import 'state.dart';

Widget buildView(GuideState state, Dispatch dispatch, ViewService viewService) {
  return Swiper(
    itemBuilder: (BuildContext context, int index) {
      if (index == 0) {
        return Container(
          color: Colors.white,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Align(
                child: Image.asset("images/guide1@2x.png"),
                alignment: Alignment.bottomCenter,
              ),
              Align(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      "校园风险实时感知",
                      style: TextStyle(
                          fontSize: 29,
                          fontWeight: FontWeight.bold,
                          color: AppColors.loginLeft),
                    ),
                    SizedBox(
                      height: 26,
                    ),
                    Text(
                      "安全态势实时感知、行为及时管控",
                      style: TextStyle(
                          fontSize: 17,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                    SizedBox(
                      height: 118,
                    )
                  ],
                ),
                alignment: Alignment.bottomCenter,
              ),
              Align(
                child: GestureDetector(
                  child: Container(
                    child: Row(
                      children: [
                        Text(
                          "跳过",
                          style: TextStyle(
                              fontSize: 14,
                              fontWeight: FontWeight.normal,
                              color: AppColors.middleTextColor),
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Image.asset(
                          "images/guide_arrow_right@2x.png",
                          width: 5.5,
                          height: 10,
                        )
                      ],
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                    ),
                    margin: EdgeInsets.only(top: 55, right: 22),
                  ),
                  onTap: () {
                    jump(state, dispatch, viewService);
                  },
                ),
                alignment: Alignment.topRight,
              )
            ],
          ),
        );
      } else if (index == 1) {
        return Container(
          color: Colors.white,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Align(
                child: Image.asset("images/guide2@2x.png"),
                alignment: Alignment.bottomCenter,
              ),
              Align(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      "手机端实时报警",
                      style: TextStyle(
                          fontSize: 29,
                          fontWeight: FontWeight.bold,
                          color: AppColors.loginLeft),
                    ),
                    SizedBox(
                      height: 26,
                    ),
                    Text(
                      "提升校园安全水平",
                      style: TextStyle(
                          fontSize: 17,
                          fontWeight: FontWeight.normal,
                          color: AppColors.deepTextColor),
                    ),
                    SizedBox(
                      height: 118,
                    )
                  ],
                ),
                alignment: Alignment.bottomCenter,
              ),
              Align(
                child: GestureDetector(
                  child: Container(
                    child: Row(
                      children: [
                        Text(
                          "跳过",
                          style: TextStyle(
                              fontSize: 14,
                              fontWeight: FontWeight.normal,
                              color: AppColors.middleTextColor),
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Image.asset(
                          "images/guide_arrow_right@2x.png",
                          width: 5.5,
                          height: 10,
                        )
                      ],
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                    ),
                    margin: EdgeInsets.only(top: 55, right: 22),
                  ),
                  onTap: () {
                    jump(state, dispatch, viewService);
                  },
                ),
                alignment: Alignment.topRight,
              )
            ],
          ),
        );
      } else {
        return Container(
          color: Colors.white,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Align(
                child: Image.asset("images/bg@2x.png"),
                alignment: Alignment.bottomCenter,
              ),
              Align(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Image.asset(
                      "images/logo@2x.png",
                      height: 81,
                      width: 81,
                    ),
                    SizedBox(
                      height: 21,
                    ),
                    Image.asset(
                      "images/slogan@2x.png",
                      width: 187.5,
                      height: 37.5,
                    ),
                    SizedBox(
                      height: 180,
                    )
                  ],
                ),
                alignment: Alignment.center,
              ),
              Align(
                child: Container(
                  margin: EdgeInsets.only(bottom: 88),
                  child: GestureDetector(
                    child: Stack(
                        alignment:Alignment.center,children: [
                      Image.asset(
                        "images/guide3_btn@2x.png",
                        width: 144,
                        height:42,
                      ),
                      Text("立即开启",style: TextStyle(fontWeight: FontWeight.normal,fontSize: 18,color: AppColors.GuideBtnTextColor),)
                    ]),
                    onTap: () {
                      jump(state, dispatch, viewService);
                    },
                  ),
                ),
                alignment: Alignment.bottomCenter,
              )
            ],
          ),
        );
      }
    },
    loop: false,
    pagination: new SwiperPagination(),
    itemCount: 3,
    scrollDirection: Axis.horizontal,
    autoplay: false,
    autoplayDelay: 3000,
    duration: 300,
  );
}

Future<void> jump(
    GuideState state, Dispatch dispatch, ViewService viewService) async {

    print("===========================去首页================================");
    SpUtil.setStringItem(Constants.FIRST_START, "1");
    Navigator.of(viewService.context)
        .pushNamedAndRemoveUntil(RouteConstants.INDEX, (route) => false);

}
